package com.example.lcode.binary;

public class Question240 {


    public boolean searchMatrix(int[][] matrix, int target) {
        int yIndex = matrix.length - 1;
        int xIndex = 0;
        return searchMatrix(matrix, xIndex, yIndex, target);
    }

    private boolean searchMatrix(int[][] matrix, int xIndex, int yIndex, int target) {
        if (xIndex >= matrix[0].length || yIndex < 0) {
            return false;
        }
        if (matrix[yIndex][xIndex] == target) {
            return true;
        } else if (matrix[yIndex][xIndex] > target) {
            return searchMatrix(matrix, xIndex, yIndex - 1, target);
        } else if (matrix[yIndex][xIndex] < target) {
            return searchMatrix(matrix, xIndex + 1, yIndex, target);
        }
        return false;
    }

    public static void main(String[] args) {
        int [][]arr = {{-1, 3}};
        Question240 question240 = new Question240();
        boolean b = question240.searchMatrix(arr, 3);
        System.out.println(b);
    }


}
